/**
 * Copyright © 2013 Creativor Studio.
 * About license information, please see LICENSE.txt.
 */
package org.rayson.share.http;

import org.rayson.api.annotation.NotNull;
import org.rayson.share.transport.BufferWritable;
import org.rayson.share.transport.ByteArrayBuffer;

/**
 * Stands for an header information in HTTP protocol.
 * 
 * @author creativor
 */
public final class HttpHeader implements BufferWritable {
	private final String name;
	private final String value;

	public HttpHeader(@NotNull final String name, @NotNull final String value) {
		this.name = name;
		this.value = value;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	@Override
	public String toString() {
		final StringBuffer sb = new StringBuffer();
		sb.append("{");
		sb.append("name:" + this.name);
		sb.append(", value:" + this.value);
		sb.append("}");
		return sb.toString();
	}

	@Override
	public void writeTo(final ByteArrayBuffer buffer) {

		buffer.write(name.getBytes());
		buffer.write(HttpConstants.MESSAGE_HEADER_SPLITER);
		buffer.write(HttpConstants.SPACE);
		buffer.write(value.getBytes());
		buffer.write(HttpConstants.CRLF);

	}
}